package com.xufx.thread.liaoxuefeng.thread3_intrerrupt;

/**
 * Created by xufx on 2021/12/24 12:39
 */
public class JoinMain {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Mythread();
        t.start();
        Thread.sleep(1000);
        t.interrupt();
        t.join();
        System.out.println("end");
    }
}
class Mythread1 extends Thread{
    @Override
    public void run(){
        Thread hello = new HelloThread();
        hello.start();
        try {
            hello.join();
        }catch (InterruptedException e){
            System.out.println("interrupted!");
        }
        hello.interrupt();
    }
}

class HelloThread extends Thread{
    @Override
    public void run(){
        int  n = 0;
        while(!isInterrupted()){
            n++;
            System.out.println(n + "hello!");
            try {
                Thread.sleep(100);
            }catch (InterruptedException e){
                break;
            }
        }
    }
}
